export default class Audio {
  constructor() {
    this.audio = wx.createInnerAudioContext()
    this.audio.obeyMuteSwitch = false
    this.isPlaying = false

    wx.setInnerAudioOption({
      obeyMuteSwitch: false
    })
  }

  play(src) {
    return new Promise((resolve, reject) => {
      let fn = () => {
        this.audio.offEnded(fn)
        this.isPlaying = false
        resolve()
      }
      this.audio.onEnded(fn)
      this.audio.src = src
      this.audio.play()
      this.isPlaying = true
    })
  }

  destroy() {
    this.audio.destroy()
  }
}